package com.feng.study.demo.juc;

import com.feng.study.value.User;
import com.google.common.collect.Lists;

import java.util.List;
import java.util.concurrent.*;

public class CountDownLatchDemo {
    private static ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
            8,
            32,
            10,
            TimeUnit.SECONDS,
            new LinkedBlockingDeque<>(100),
            Executors.defaultThreadFactory(),
            new ThreadPoolExecutor.AbortPolicy());

    public static void main(String[] args) {
        int a=9;
        CountDownLatch countDownLatch = new CountDownLatch(a);
        for (int i = 0; i < a; i++) {
            int finalI = i;
            threadPoolExecutor.submit(()->{
                System.out.println("当前线程i:"+ finalI+"--线程id:"+Thread.currentThread().getId());
                if (finalI==1 ||finalI==5){
                    try {
                        Thread.sleep(10000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                System.out.println("=====当前线程i:"+ finalI+"--线程id:"+Thread.currentThread().getId());
                countDownLatch.countDown();
            });
        }
        try {
            countDownLatch.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("全部执行完毕");
    }
}
